| var layer; | 
| var form; | 
| var depotId; | 
| var listData; | 
| $(function () { | 
|     layui.use(['layer', 'table', 'form', 'laydate'], function () { | 
|         table = layui.table; | 
|         form = layui.form; | 
|         layer = layui.layer; | 
|         var laydate = layui.laydate; | 
|         laydate.render({ | 
|             elem: '#start', | 
|             theme: '#7b8e9f' | 
|         }); | 
|   | 
|         laydate.render({ | 
|             elem: '#end', | 
|             theme: '#7b8e9f' | 
|         }); | 
|   | 
|         //监听提交 | 
|         form.on('submit(submitData)', function (data) { | 
|             addSubmit(data.field); | 
|             return false; | 
|         }); | 
|         query(); | 
|         //初始化ws | 
|         initWS(deptId, bizType,null, userId); | 
|     }); | 
| }); | 
|   | 
| //socket信息返回處理 | 
| function socketOnMessage(pocket) { | 
|     window.parent.sysNotify(pocket.data); | 
| }; | 
|   | 
| //查询 | 
| function query() { | 
|   | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/grain-analysis/list-data", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify({depotId: depotId}), | 
|         success: function (result) { | 
|             if (result.code == "0000") { | 
|                 listData = result.data; | 
|                 renderData(); | 
|             } else { | 
|                 $("#div_main").text(result.msg); | 
|                 layer.msg(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.msg("获取数据失败,请重新尝试!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| //动态渲染自动模式数据 | 
| function renderData() { | 
|     var strHtml = ""; | 
|     $.each(listData, 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 == "Y") {//表示手动运行 | 
|             strHtml += "<img src=\"../../static/images/fenxi-icon.gif\">"; | 
|             strHtml += "<div class=\"layadmin-maillist-img layadmin-font-blod\">分析中</div>"; | 
|         } else { | 
|             strHtml += "<img src=\"../../static/images/fenxi-icon.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=\"runData('" + item.id + "')\">开启</button>"; | 
|         strHtml += "<button type=\"button\" class=\"layui-btn layui-btn-normal\" onclick=\"stopData('" + item.id + "')\">关闭</button>"; | 
|         strHtml += "<button type=\"button\" class=\"layui-btn layui-btn-warm\" onclick=\"editData('" + item.id + "')\">编辑</button>"; | 
|         strHtml += "<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"selectData('" + item.id + "','" + item.depotIds + "')\">配置</button>"; | 
|         strHtml += "</div></div></div>\n"; | 
|     }); | 
|     $("#div_main").html(strHtml); | 
| }; | 
|   | 
|   | 
| //点击运行,弹出选择原因 | 
| function runData(dataId) { | 
|     layer.confirm('确定开启?', function (index) { | 
|         updateStatus(dataId, "Y"); | 
|     }); | 
| }; | 
|   | 
| //停止 | 
| function stopData(dataId) { | 
|     layer.confirm('确定关闭?', function (index) { | 
|         updateStatus(dataId, "N"); | 
|     }); | 
| }; | 
|   | 
| function openAll() { | 
|     layer.confirm('确定开启?', function (index) { | 
|         updateAllStatus("Y"); | 
|     }); | 
| }; | 
|   | 
| function closeAll() { | 
|     layer.confirm('确定关闭?', function (index) { | 
|         updateAllStatus("N"); | 
|     }); | 
|   | 
| }; | 
|   | 
| //编辑 | 
| function editData(dataId) { | 
|     var curItem = null; | 
|     $.each(listData, function (index, item) { | 
|         if (dataId == item.id) { | 
|             curItem = item; | 
|             return true; | 
|         } | 
|     }); | 
|     //开始赋值 | 
|     form.val('form_data', curItem); | 
|     form.render(); | 
|   | 
|     layer.open({ | 
|         type: 1, | 
|         title: '方案调整', | 
|         area: ['700px', '430px'], | 
|         shade: 0, | 
|         content: $('#addData'), | 
|         btn: ['提交', '删除', '取消'], | 
|         yes: function () { | 
|             updateSubmit(); | 
|         }, | 
|         btn2: function () { | 
|             delData(dataId); | 
|         }, | 
|         btn3: function () { | 
|             layer.close(0); | 
|         }, | 
|         closeBtn: 1 | 
|     }); | 
|   | 
| }; | 
|   | 
| //配置,选择仓库 | 
| function selectData(id, depotIds) { | 
|   | 
|     $('#depotSelect input').each(function () { | 
|         $(this).prop("checked", false); | 
|         if (depotIds) { | 
|             if (depotIds.indexOf($(this).val()) != -1) { | 
|                 $(this).prop("checked", true); | 
|             } | 
|         } | 
|   | 
|     }); | 
|   | 
|     form.render(); | 
|     // 弹出选择框 | 
|     layer.open({ | 
|         type: 1, | 
|         title: '配置仓库', | 
|         area: ['720px', '450px'], | 
|         shade: 0, | 
|         content: $('#depotSelect'), | 
|         btn: ['全选', '重选', '确定', '取消'], | 
|         yes: function () { | 
|             $('#depotSelect input').each(function () { | 
|                 $(this).prop("checked", true); | 
|             }); | 
|             form.render(); | 
|         }, | 
|         btn2: function () { | 
|             $('#depotSelect input').each(function () { | 
|                 $(this).prop("checked", false); | 
|             }); | 
|             form.render(); | 
|             return false; | 
|         }, | 
|         btn3: function () { | 
|             return updateDepots(id); | 
|         }, | 
|         btn4: function () { | 
|             layer.close(0); | 
|         }, | 
|         closeBtn: 0 | 
|     }); | 
| } | 
|   | 
| function updateDepots(id) { | 
|     var depotIds = ""; | 
|     $('#depotSelect input').each(function () { | 
|         if ($(this).prop("checked")) { | 
|             depotIds += $(this).val() + ","; | 
|         } | 
|     }); | 
|   | 
|     if (depotIds == "") { | 
|         layer.msg("请先选择配置的仓库……"); | 
|         return false; | 
|     } | 
|   | 
|     var curItem = null; | 
|     $.each(listData, function (index, item) { | 
|         if (id == item.id) { | 
|             curItem = item; | 
|             return true; | 
|         } | 
|     }); | 
|   | 
|     curItem.depotIds = depotIds; | 
|   | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/grain-analysis/update-data", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify(curItem), | 
|         success: function (result) { | 
|             if (result.code == "0000") { | 
|                 layer.msg("更新成功!"); | 
|                 layer.closeAll(); | 
|                 query(); | 
|             } else { | 
|                 layer.msg(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.msg("系统后台执行失败,请联系统管理原!"); | 
|         } | 
|     }); | 
|     return true; | 
| } | 
|   | 
| //删除 | 
| function delData(dataId) { | 
|     if (dataId) { | 
|         layer.confirm('确定要删除么?', function (index) { | 
|             var curItem = form.val('form_data'); | 
|             //编辑删除标记 | 
|             $.ajax({ | 
|                 type: "POST", | 
|                 url: "../../basic/grain-analysis/del-data", | 
|                 dataType: "json", | 
|                 contentType: "application/json;charset=UTF-8", | 
|                 data: JSON.stringify({"id": dataId}), | 
|                 success: function (result) { | 
|                     if (result.code == "0000") { | 
|                         layer.msg("数据删除成功!!"); | 
|                         query(); | 
|                         layer.closeAll(); | 
|                     } else { | 
|                         layer.msg(result.msg); | 
|                     } | 
|                 }, | 
|                 error: function (result) { | 
|                     layer.msg("系统后台执行失败,请联系统管理原!"); | 
|                 } | 
|             }); | 
|         }); | 
|     } | 
| }; | 
|   | 
| //新增模式 | 
| function addData() { | 
|     //重置 | 
|     $("#form_data")[0].reset(); | 
|     form.render(); | 
|   | 
|     // 弹出选择框 | 
|     layer.open({ | 
|         type: 1, | 
|         title: '新增方案', | 
|         area: ['700px', '430px'], | 
|         shade: 0, | 
|         content: $('#addData'), | 
|         btn: ['提交', '取消'], | 
|         yes: function () { | 
|             addSubmit(); | 
|         }, | 
|         btn2: function () { | 
|             layer.close(0); | 
|         }, | 
|         closeBtn: 1 | 
|     }); | 
| }; | 
|   | 
| //提交模式新增数据 | 
| function updateSubmit() { | 
|     var formData = form.val('form_data'); | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/grain-analysis/update-data", | 
|         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.msg(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.msg("系统后台执行失败,请联系统管理原!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| //提交模式新增数据 | 
| function updateStatus(dataId, status) { | 
|     var formData = { | 
|         "id": dataId, | 
|         "runStatus": status | 
|     }; | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/grain-analysis/update-data", | 
|         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.msg(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.msg("系统后台执行失败,请联系统管理原!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
|   | 
| //提交模式新增数据 | 
| function updateAllStatus(status) { | 
|     var formData = { | 
|         "companyId": companyId, | 
|         "runStatus": status | 
|     }; | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/grain-analysis/update-all-status", | 
|         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.msg(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.msg("系统后台执行失败,请联系统管理原!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| //提交模式新增数据 | 
| function addSubmit() { | 
|     var formData = form.val('form_data'); | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/grain-analysis/add-data", | 
|         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.msg(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.msg("系统后台执行失败,请联系统管理原!"); | 
|         } | 
|     }); | 
| }; |