128 lines
5.0 KiB
Plaintext
128 lines
5.0 KiB
Plaintext
@page
|
||
@model Waste.Web.Entry.Pages.Device.ProductModel
|
||
@{
|
||
ViewData["Title"] = "标准秤列表";
|
||
}
|
||
<div class="layui-card">
|
||
<div class="layui-form layui-card-header layuiadmin-card-header-auto">
|
||
<div class="layui-form-item">
|
||
<div class="layui-inline">
|
||
<div class="layui-input-inline">
|
||
<input type="text" class="layui-input" name="Name" id="Name" placeholder="请输入产品名称" />
|
||
</div>
|
||
</div>
|
||
<div class="layui-inline">
|
||
<button class="btn btn-primary btn-lg js-search" type="button">查询</button>
|
||
@*<button class="btn btn-primary btn-lg js-add" type="button">添加</button> *@
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="layui-card-body">
|
||
<table class="layui-table" id="list" lay-filter="list">
|
||
</table>
|
||
</div>
|
||
</div>
|
||
@section Scripts {
|
||
<script type="text/javascript">
|
||
layui.use(['common'], function () {
|
||
var common = layui.common;
|
||
common.initTable({
|
||
url: '/api/open/getproduct', method: 'post',
|
||
cols: [[
|
||
{
|
||
field: 'image', title: '图片',templet: function(d) { // 自定义渲染逻辑
|
||
return '<img src="' + d.image + '" style="width: 50px; height: 50px;">';
|
||
}
|
||
},
|
||
{
|
||
field: 'video', title: '视频'
|
||
},
|
||
{
|
||
field: 'productname', title: '产品名称'
|
||
},
|
||
{
|
||
field: 'netweight', title: '净重'
|
||
},
|
||
{
|
||
field: 'weight', title: '毛重'
|
||
},
|
||
{
|
||
field: 'amount', title: '数量'
|
||
},
|
||
{
|
||
field: 'unit', title: '重量单位'
|
||
},
|
||
{
|
||
field: 'idvalues', title: '单价@总价'
|
||
},
|
||
{
|
||
field: 'upperlimit', title: '上限'
|
||
},
|
||
{
|
||
field: 'username', title: '用户名称'
|
||
},
|
||
{
|
||
field: 'createtime', title: '创建时间'
|
||
},
|
||
{
|
||
field: 'id', // 改为绑定id字段
|
||
title: '操作',
|
||
templet: function(d) {
|
||
return `<a class="layui-btn layui-btn-danger layui-btn-xs"
|
||
onclick="deleteProduct('${d.id}')">删除</a>`;
|
||
}
|
||
}
|
||
]],
|
||
parseData: function(n) {
|
||
console.log("接口返回的原始数据:", n);
|
||
return {
|
||
data: n.items, // 数据列表在 n.Items 中
|
||
totalnum: n.totalnum, // 数据总数在 n.totalnum 中
|
||
statuscode: 200
|
||
};
|
||
},
|
||
});
|
||
$(".js-search").on("click", function () {
|
||
common.reloadtable("list", {
|
||
where: {
|
||
queryParam: [{
|
||
"Name": 'ProductName',
|
||
"Type": QueryCond.Like,
|
||
"Value": $("#Name").val()
|
||
}]
|
||
}
|
||
});
|
||
});
|
||
});
|
||
</script>
|
||
<script>
|
||
// 删除函数
|
||
function deleteProduct(id) {
|
||
layer.confirm('确认删除这条记录?', { icon: 3 }, function() {
|
||
$.post('/api/open/deleteproduct', { id: id }, function(res) {
|
||
if (res.status.code === 1) {
|
||
layer.msg('删除成功', { icon: 1 });
|
||
layui.common.reloadtable("list"); // 刷新表格
|
||
} else {
|
||
layer.msg(res.status.message, { icon: 2 });
|
||
}
|
||
});
|
||
});
|
||
}
|
||
function deleteProduct(id) {
|
||
layer.confirm('确认删除这条记录?', { icon: 3 }, function() {
|
||
$.post('/api/open/deleteproduct', { id: id }, function(res) {
|
||
// 修改点:直接使用 res.code 和 res.message
|
||
if (res.code === 0) { // 注意这里判断的是 0(成功)
|
||
layer.msg('删除成功', { icon: 1 });
|
||
layui.common.reloadtable("list");
|
||
} else {
|
||
layer.msg(res.message || '删除失败', { icon: 2 });
|
||
}
|
||
}).fail(function() {
|
||
layer.msg('请求失败,请检查网络', { icon: 2 });
|
||
});
|
||
});
|
||
}
|
||
</script>
|
||
} |