| var layer; | 
| var form; | 
| var depotId; | 
| var listAuto; | 
| $(function () { | 
|     layui.use(['layer', 'table', 'form'], function () { | 
|         table = layui.table; | 
|         form = layui.form; | 
|         layer = layui.layer; | 
|   | 
|         //监听仓库选择 | 
|         form.on('select(select_depotId)', function () { | 
|             query(); | 
|         }); | 
|         //监听提交 | 
|         form.on('submit(submitAuto)', function (data) { | 
|             addSubmit(data.field); | 
|             return false; | 
|         }); | 
|         //监听工具条 | 
|         table.on('tool(table_auto_conf)', function (obj) { | 
|             var data = obj.data; | 
|             if (obj.event === 'ZERO') { | 
|                 data.targetStatus = "ZERO"; | 
|             } else if (obj.event === 'OPEN' || obj.event === 'W_OPEN') { | 
|                 if (data.type == "04") { | 
|                     layer.alert("气调,当前设备不支持该目标操作……"); | 
|                 } else if (data.type == "0C" || data.type == "02") { | 
|                     data.targetStatus = "W_OPEN"; | 
|                 } else { | 
|                     data.targetStatus = "OPEN"; | 
|                 } | 
|             } else if (obj.event === 'F_OPEN') { | 
|                 if (data.type == "02" || data.type == "04") { | 
|                     data.targetStatus = "F_OPEN"; | 
|                 } else { | 
|                     layer.alert("气调,当前设备不支持该目标操作……"); | 
|                 } | 
|             } else if (obj.event === 'F_OPEN_F') { | 
|                 if (data.type == "02" || data.type == "04") { | 
|                     data.targetStatus = "F_OPEN_F"; | 
|                 } else { | 
|                     layer.alert("气调,当前设备不支持该目标操作……"); | 
|                 } | 
|             } | 
|             obj.update(data); | 
|         }); | 
|     }); | 
| }); | 
|   | 
| //根据仓库查询 | 
| function query() { | 
|     layer.msg("开始执行查询……"); | 
|     var param = { | 
|         companyId: companyId, | 
|         deptId: deptId | 
|     }; | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/n2/list-auto", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify(param), | 
|         success: function (result) { | 
|             if (result.code == "0000") { | 
|                 listAuto = result.data; | 
|                 renderAuto(); | 
|             } else { | 
|                 $("#div_main").text(result.msg); | 
|                 layer.alert(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.alert("获取数据失败,请重新尝试!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| //动态渲染自动模式数据 | 
| function renderAuto() { | 
|     var strHtml = ""; | 
|     $.each(listAuto, function (index, item) { | 
|         strHtml += "<div class=\"layui-col-md4 layui-col-sm6\">\n <div class=\"layadmin-contact-box\">\n <div class=\"layui-col-md4 layui-col-sm6\">\n <div class=\"layadmin-text-center\">"; | 
|         //控制模式效果 | 
|         if (item.runStatus == "02") {//表示手动运行 | 
|             strHtml += "<img src=\"../../static/images/icon-n2-open.png\">"; | 
|             strHtml += "<div class=\"layadmin-maillist-img layadmin-font-blod\">手动开启</div>"; | 
|         } else if (item.runStatus == "03") { | 
|             strHtml += "<img src=\"../../static/images/icon-n2-open.png\">"; | 
|             strHtml += "<div class=\"layadmin-maillist-img layadmin-font-blod\">系统开启</div>"; | 
|         } else { | 
|             strHtml += "<img src=\"../../static/images/icon-n2-close.png\">"; | 
|             strHtml += "<div class=\"layadmin-maillist-img layadmin-font-blod\">未启动</div>"; | 
|         } | 
|         strHtml += "</div></div>\n <div class=\"layui-col-md8 layadmin-padding-left20 layui-col-sm6\">"; | 
|         strHtml += "<h3 class=\"layadmin-title\"><strong>" + item.name + "</strong></h3>"; | 
|         strHtml += "<div class=\"layadmin-address\">\n <strong><i class=\"layui-icon layui-icon-tips\"></i> 说明</strong> <br>"; | 
|         strHtml += "<p class=\"layadmin-textimg\">" + item.remark + "</p></div>"; | 
|         strHtml += "<p class=\"layadmin-textimg\">"; | 
|         strHtml += "<button type=\"button\" class=\"layui-btn\" onclick=\"runAuto('" + item.id + "')\">开启</button>"; | 
|         strHtml += "<button type=\"button\" class=\"layui-btn layui-btn-normal\" onclick=\"stopAuto('" + item.id + "')\">关闭</button>"; | 
|         strHtml += "<button type=\"button\" class=\"layui-btn layui-btn-warm\" onclick=\"editAuto('" + item.id + "')\">编辑</button>"; | 
|         strHtml += "<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"editAutoConf('" + item.id + "')\">配置</button>"; | 
|         strHtml += "</div></div></div>\n"; | 
|     }); | 
|     $("#div_main").html(strHtml); | 
| }; | 
|   | 
| //运行 | 
| function runAuto(autoId) { | 
|     depotId = $("#depotId").val(); | 
|     if (!depotId) { | 
|         layer.alert("请确认需要执行的仓库!!"); | 
|         return; | 
|     } | 
|   | 
|     layer.confirm('确定要执行么?', function (index) { | 
|         runAuto2(autoId); | 
|         layer.close(index); | 
|     }); | 
| }; | 
|   | 
| //运行 | 
| function runAuto2(autoId) { | 
|     var index = layer.load(0); | 
|     var parm = { | 
|         depotId: depotId, | 
|         autoId: autoId | 
|     }; | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/n2/run-auto", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify(parm), | 
|         success: function (result) { | 
|             layer.close(index); | 
|             if (result.code == "ORDER_SUCCESS") { | 
|                 layer.alert("设备操控指令发送成功!"); | 
|             } else { | 
|                 layer.alert(result.msg == null ? "系统后台执行失败,请联系统管理员" : result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.alert("系统后台执行失败,请联系统管理员!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| //停止 | 
| function stopAuto(autoId) { | 
|     depotId = $("#depotId").val(); | 
|     if (!depotId) { | 
|         layer.alert("请先选择仓库!!"); | 
|         return; | 
|     } | 
|     var index = layer.load(0); | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/n2/stop-auto", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify({depotId: depotId, autoId: autoId}), | 
|         success: function (result) { | 
|             layer.close(index); | 
|             if (result.code == "ORDER_SUCCESS") { | 
|                 layer.alert("设备操控指令发送成功!"); | 
|             } else { | 
|                 layer.alert(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.alert("系统后台执行失败,请联系统管理原!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| //编辑 | 
| function editAuto(autoId) { | 
|     depotId = $("#depotId").val(); | 
|     if (!depotId) { | 
|         layer.alert("请先选择仓库!!"); | 
|         return; | 
|     } | 
|     var curItem = null; | 
|     $.each(listAuto, function (index, item) { | 
|         if (autoId == item.id) { | 
|             curItem = item; | 
|             return true; | 
|         } | 
|     }); | 
|     //开始赋值 | 
|     form.val('form_auto', curItem); | 
|     form.render(); | 
|   | 
|     layer.open({ | 
|         type: 1, | 
|         title: '自动模式调整', | 
|         area: ['700px', '450px'], | 
|         shade: 0, | 
|         content: $('#addAuto'), | 
|         btn: ['提交', '删除', '取消'], | 
|         yes: function () { | 
|             addSubmit(); | 
|         }, | 
|         btn2: function () { | 
|             layer.confirm('确定要删除么?', function (index) { | 
|                 delAuto(); | 
|             }) | 
|         }, | 
|         btn3: function () { | 
|             layer.close(0); | 
|         }, | 
|         closeBtn: 1 | 
|     }); | 
|   | 
| }; | 
|   | 
| //编辑配置信息 | 
| function editAutoConf(autoId) { | 
|     depotId = $("#depotId").val(); | 
|     if (!depotId) { | 
|         layer.alert("请先选择仓库!!"); | 
|         return; | 
|     } | 
|     //获取配置数据信息 | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/n2/list-auto-conf", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify({depotId: depotId, autoId: autoId}), | 
|         success: function (result) { | 
|             if (result.code == "0000") { | 
|                 //弹出对话框,并渲染数据 | 
|                 renderAutoConf(autoId, result.data); | 
|             } else { | 
|                 layer.alert(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.alert("系统后台执行失败,请联系统管理原!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| //渲染配置信息 | 
| function renderAutoConf(autoId, listAutoConf) { | 
|     // 弹出选择框 | 
|     layer.open({ | 
|         type: 1, | 
|         title: '配置自动模式设备控制', | 
|         area: ['860px', '600px'], | 
|         shade: 0, | 
|         content: $('#autoConf'), | 
|         btn: ['提交配置', '取消'], | 
|         yes: function () { | 
|             submitAutoConf(autoId); | 
|         }, | 
|         btn2: function () { | 
|             layer.close(0); | 
|         }, | 
|         closeBtn: 1 | 
|     }); | 
|     //渲染表格 | 
|     table.render({ | 
|         elem: '#table_auto_conf', | 
|         height: 450, | 
|         data: listAutoConf, | 
|         page: false, | 
|         limit: 100, | 
|         even: "true", | 
|         cols: [[{ | 
|             width: '25%', | 
|             field: 'name', | 
|             title: '设备名称', | 
|         }, { | 
|             width: '15%', | 
|             field: 'location', | 
|             title: '位置', | 
|             align: 'center', | 
|             templet: locationStatus | 
|         }, { | 
|             width: '25%', | 
|             field: 'targetStatus', | 
|             title: '目标状态', | 
|             align: 'center', | 
|             templet: targetStatus | 
|         }, { | 
|             width: '35%', | 
|             title: '配置操作', | 
|             align: 'center', | 
|             toolbar: '#barAutoConf' | 
|         } | 
|         ]] | 
|     }); | 
| }; | 
|   | 
| function locationStatus(d) { | 
|     if (d.location == "01") { | 
|         return "正面"; | 
|     } else { | 
|         return "背面"; | 
|     } | 
| }; | 
|   | 
| function targetStatus(d) { | 
|     var targetStatus = d.targetStatus; | 
|     var result = "<span style=\"color: #C9C9C9;\">无控制</span>"; | 
|     if (targetStatus == "OPEN" || targetStatus == "W_OPEN") { | 
|         result = "<span style=\"color: #1E9FFF;\">风口/阀门开</span>"; | 
|     } | 
|     if (targetStatus == "F_OPEN") { | 
|         result = "<span style=\"color: #FFB800;\">强风开</span>"; | 
|     } | 
|     if (targetStatus == "F_OPEN_F") { | 
|         result = "<span style=\"color: #009688;\">弱风开</span>"; | 
|     } | 
|     return result; | 
| }; | 
|   | 
| //提交配置 | 
| function submitAutoConf(autoId) { | 
|     var listData = table.cache["table_auto_conf"]; | 
|     layer.msg("开始提交配置信息……"); | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/n2/update-auto-conf", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify({deviceList: listData, autoId: autoId}), | 
|         success: function (result) { | 
|             if (result.code == "0000") { | 
|                 layer.alert("数据提交完成……"); | 
|             } else { | 
|                 layer.alert(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.alert("系统后台执行失败,请联系统管理原!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| //删除 | 
| function delAuto() { | 
|     var formData = form.val('form_auto'); | 
|     //编辑删除标记 | 
|     formData["delTag"] = "Y"; | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/n2/update-auto", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify(formData), | 
|         success: function (result) { | 
|             if (result.code == "0000") { | 
|                 layer.alert("数据删除成功!!"); | 
|                 query(); | 
|                 layer.closeAll(); | 
|             } else { | 
|                 layer.alert(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.alert("系统后台执行失败,请联系统管理原!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| //新增模式 | 
| function addAuo() { | 
|     depotId = $("#depotId").val(); | 
|     if (!depotId) { | 
|         layer.alert("请先选择仓库!!"); | 
|         return; | 
|     } | 
|     //重置 | 
|     $("#form_auto")[0].reset(); | 
|     form.render(); | 
|   | 
|     // 弹出选择框 | 
|     layer.open({ | 
|         type: 1, | 
|         title: '新增手动模式', | 
|         area: ['700px', '450px'], | 
|         shade: 0, | 
|         content: $('#addAuto'), | 
|         btn: ['提交', '取消'], | 
|         yes: function () { | 
|             addSubmit(); | 
|         }, | 
|         btn2: function () { | 
|             layer.close(0); | 
|         }, | 
|         closeBtn: 1 | 
|     }); | 
| }; | 
|   | 
| //提交模式新增数据 | 
| function addSubmit() { | 
|     var formData = form.val('form_auto'); | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/n2/update-auto", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify(formData), | 
|         success: function (result) { | 
|             if (result.code == "0000") { | 
|                 layer.msg("手动模式添成功!"); | 
|                 layer.closeAll(); | 
|                 query(); | 
|             } else { | 
|                 layer.alert(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.alert("系统后台执行失败,请联系统管理原!"); | 
|         } | 
|     }); | 
| }; |