hn_cloud_web/czl-web/pages/machineTool/toolDetailForm.html

349 lines
14 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>工机具绑定表单</title>
<link rel="stylesheet" href="../../layui-v2.8.18/layui/css/layui.css" media="all"/>
</head>
<style>
.layui-form-label {
position: relative;
float: left;
display: block;
padding: 9px 15px;
width: 100%;
font-weight: 400;
line-height: 20px;
text-align: right;
}
.layui-form-item .layui-input-inline {
margin-right: 22px;
}
/* 弹出层外部容器样式 */
.layui-layer {
border-radius: 10px; /* 设置圆角半径,根据需要调整 */
}
/* 弹出层内部容器样式(如果需要) */
.layui-layer-content {
border-radius: 10px; /* 设置圆角半径,根据需要调整 */
overflow: hidden; /* 防止内容溢出圆角区域 */
}
.layui-table-tool-self{
display: none;
}
.layui-table td, .layui-table th, .layui-table-col-set, .layui-table-fixed-r, .layui-table-grid-down, .layui-table-header, .layui-table-mend, .layui-table-page, .layui-table-tips-main, .layui-table-tool, .layui-table-total, .layui-table-view, .layui-table[lay-skin=line], .layui-table[lay-skin=row] {
border-width: 1px;
border-style: none;
border-color: #eee;
}
</style>
<body>
<form class="layui-form" action="" onsubmit="return false">
<div class="layui-form-item" style="margin-top: 1%;">
<div class="layui-input-inline">
<label class="layui-form-label"><i class="tip-required"
style="color: red;font-size: 20px">*</i>选择项目部:</label>
</div>
<div class="layui-input-inline" style="border: 0 dashed dimgrey;width: 74%;">
<select id="projectIds" name="projectIds" class="layui-select" lay-search=""
lay-filter="volLevelIds" lay-verify="required"></select>
</div>
</div>
<div class="layui-form-item" style="margin-top: 1%;display: flex;flex-direction:column;">
<div>
<div class="layui-input-inline">
<label class="layui-form-label"><i class="tip-required"
style="color: red;font-size: 20px">*</i>绑定数量:</label>
</div>
<div class="layui-input-inline" style="border: 0 dashed dimgrey;width: 74%;">
<input id="useNum" name="useNum" type="number" lay-affix="number" placeholder="输入数值" value="0" class="layui-input">
</div>
</div>
</div>
<div style="display: flex">
<span style="color: red;margin-left: 14%;font-size: 20px;">剩余未绑定的数量:<span id="surplusNum"></span></span>
<div class="layui-input-block" style="margin-left: 57%;">
<button type="submit" class="layui-btn subBtn" id="commit" lay-submit lay-filter="formDemo">提交</button>
</div>
</div>
<hr class="layui-border-green">
<!-- <div class="layui-panel" style="padding: 10px;">-->
<table id="demo" lay-filter="test" style="padding: 10px"></table>
<!-- </div>-->
</form>
</body>
</html>
<script src="../../js/jquery/jquery-3.6.0.js"></script>
<script src="../../layui-v2.8.18/layui/layui.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script src="../../js/common_methon.js"></script>
<script type="text/javascript" src="../../js/publicJs.js"></script>
<script type="text/javascript" src="../../js/select.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript">
layui.config({
base: '../../js/layuiModules/', // 第三方模块所在目录
version: 'v1.6.4' // 插件版本号
}).extend({
soulTable: 'notice,layNotify,notice', // 模块
});
var form;
var table;
var newData;
var laydate
var notice;
var layarea;
var layNotify;
var id = localStorage.getItem("toolsId");
// var surplusNum = localStorage.getItem("surplusNum");
let surplusNum = 0;
var finalData;
var type = "1";
let pers = checkPermission();
layui.use(['table', 'form','notice', 'layNotify', 'layarea'], function () {
table = layui.table;
form = layui.form;
laydate = layui.laydate;
notice = layui.notice;
layNotify = layui.layNotify;
layarea = layui.layarea;
layarea.render({
elem: '#area-picker3',
change: function (res) {
//选择结果
console.log(res);
}
});
getList();
getProjectName(form, "");
// 验证成功后才会执行下面的操作
form.on('submit(formDemo)', function (data) {
var useNum = data.field.useNum;
console.log("surplusNum:"+surplusNum)
if (parseInt(useNum) > parseInt(surplusNum)) {
layer.msg('绑定数量不能大于剩余未绑定的数量', {icon: 2});
return false; // 阻止表单提交
} else if( useNum < 0 ){
layer.msg('绑定数量不能小于0', {icon: 2});
return false; // 阻止表单提交
} else {
data.field.id = id;
addInfo(data); //新增方法
}
});
table.render({
elem: '#demo'
, url: ctxPath + '/dataIndex/getActiveList' //数据接口
, method: 'post' //方式默认是get
, toolbar: 'default' //开启工具栏,此处显示默认图标,可以自定义模板,详见文档
, where: {
"id": id,
} //post请求必须加where post请求需要的参数
, cellMinWidth: 80
, cols: [[ //表头
{
field: 'number', width:80,title: '序号', align: 'center', type: 'numbers'
}
, {field: 'toolsProcesName', align: 'center', title: '工序'}
, {field: 'toolsName', align: 'center', title: '设备名称'}
, {field: 'toolsModel', align: 'center', title: '规格型号'}
, {field: 'toolsUnit', align: 'center', title: '单位'}
, {field: 'proName', align: 'center', title: '项目部'}
, {field: 'branchName', align: 'center', title: '分公司'}
, {field: 'useNum', align: 'center', title: '该项目部正在使用数量'}
// , {field: '', align: 'center', title: '设备剩余数量',templet: function (d) {
// return (d.toolsNum - d.useNum);
// }
// }
, {
fixed: 'right', width:180, title: '操作', align: 'center', templet: d => {
let text = "";
if(d.state == '0'){
if ($.inArray('sysActive:untie', pers) > 0) {
text +='<a lay-event="Unbind" style="color: #009688; cursor: pointer; font-size: 15px;">解绑</a>';
}
}
return text;
}
}
]]
, id: 'menuTable'
, page: true //开启分页
, loading: true //数据加载中。。。
, limits: [5, 10, 20] //一页选择显示3,5或10条数据
, limit: 10 //一页显示5条数据
, response: {
statusCode: 200 //规定成功的状态码默认0
}, parseData: function (res) { //将原始数据解析成 table 组件所规定的数据res为从url中get到的数据
let result;
if (res.data !== '' && res.data != null && res.data !== "null") {
if (this.page.curr) {
result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
} else {
result = res.data.slice(0, this.limit);
}
}
return {
"code": res.code, //解析接口状态
"msg": res.msg, //解析提示文本
"count": res.count, //解析数据长度
"data": result, //解析数据列表
};
}
,toolbar: "#toolbar"
});
table.on('tool(test)', function (obj) {
var data = obj.data; //当前行数据
console.log(data)
var rowIndex = obj.index;
var layEvent = obj.event; //当前点击的事件名
if (layEvent === 'Unbind') {
layer.confirm('确定要解除绑定吗?', {
btn : [ '确定', '取消' ]
}, function() {
$.ajax({
type: 'POST',
async: false, // 默认异步true,false表示同步
url: ctxPath + '/dataIndex/delActiveById',// 请求地址
contentType: "application/x-www-form-urlencoded",
dataType: 'json', // 服务器返回数据类型
data: {'proId': data.proId,'toolsId':data.toolsId}, //获取提交的表单字段
success: function (data) {
var resMsg = data.resMsg;
if ("数据获取成功" == resMsg) {
reloadTip("解绑","解绑成功",'success',layNotify);
layer.closeAll();
reloadTable();
getList();
}else {
reloadTip("解绑","解绑失败",'error',layNotify);
setTimeout(function(){
layer.closeAll();
}, 2000);
}
}
});
});
}
});
});
/**
* 新增或修改的提交方法
* @param formData
* @returns {boolean}
*/
function addInfo(formData) {
formData.field.id = id;
$.ajax({
type: 'post',
async: false, // 默认异步true,false表示同步
url: ctxPath + "/dataIndex/addActive", // 请求地址
contentType: "application/json; charset=utf-8",
dataType: 'json', // 服务器返回数据类型
data: JSON.stringify(formData.field), //获取提交的表单字段
success: function (data) {
if (data.resMsg === "数据获取成功") {
reloadTip("绑定","绑定成功",'success',layNotify);
getList();
reloadTable();
getProjectName(form, "");
$("#useNum").val("0");
}
},
error: function (XMLHttpRequest, textStatus, e) {
reloadTip("绑定","绑定失败",'error',layNotify);
reloadTable();
}
});
}
function getList() {
$.ajax({
type: 'POST',
async: false, // 默认异步true,false表示同步
url: ctxPath + '/dataIndex/getSurplusQuantity',// 请求地址
dataType: 'json', // 服务器返回数据类型
data: {'id': id}, //获取提交的表单字段
success: function (data) {
var resMsg = data.resMsg;
if ("数据获取成功" === resMsg) {
let info = data.obj.sysUser;
surplusNum = info.surplusNum;
document.getElementById("surplusNum").innerText = surplusNum;
}
},
error: function (XMLHttpRequest, textStatus, e) {
// layer.close(loadingMsg);
layer.msg('数据请求发生异常,请稍后重试', {icon: 16, scrollbar: false});
}
});
}
/**
* 获取承载力工程名称
* @param id 工种id
*/
function getEngineerLevel(from,id) {
console.log("id:"+id)
console.log("from:"+from)
$("#engineerIds").empty();
$.ajax({
type: 'post',
url: ctxPath + '/selectUtil/getBearingCapacity',
async: false,
success: function (data) {
var res = data;
var html = '';
html += '<option value="">请选择工程</option>';
for(var i=0;i<res.length;i++){
if(id == res[i].id || id == res[i].name){
html += '<option selected value=\'' + res[i].id + '\'>' + res[i].name + '</option>';
}else{
html += '<option value=\'' + res[i].id + '\'>' + res[i].name + '</option>';
}
}
$("#engineerIds").html(html);
form.render("select");
},
error: function (err) {
console.log("获取承载力工程数据失败:", err);
}
});
}
//刷新表格
function reloadTable() {
table.reload('menuTable', {
url: ctxPath + '/dataIndex/getActiveList'
, method: 'post' //方式默认是get
, page: true
, where: {
"id": id,
} //设定异步数据接口的额外参数
});
}
function reloadTip(tip,message,type){
parent.layNotify.notice({
title: tip+"提示",
type: type,
message: message
});
}
</script>