| | |
| | | layui.use(['table','laydate', 'form'], function(){ |
| | | layui.use(['table', 'laydate', 'form'], function(){ |
| | | var $ = layui.jquery; |
| | | var layer = layui.layer; |
| | | var form = layui.form; |
| | | |
| | | getLocTable(1); |
| | | // 初始加载 |
| | | loadRowsOptions(); // 加载「排」选项(始终需要) |
| | | loadLayersOptions(); // 加载「层」选项(提前准备) |
| | | getLocTable('byRow', 1); // 默认按排 + 第1排 |
| | | |
| | | function getLocTable(row){ |
| | | // 加载所有可用排 |
| | | function loadRowsOptions() { |
| | | $.ajax({ |
| | | url: baseUrl+"/report/viewLocMapList.action", |
| | | url: baseUrl + "/report/viewLocMapList/rows.action", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: {row: row}, |
| | | method: 'POST', |
| | | async: false, |
| | | success: function (res) { |
| | | if (res.code === 200) { |
| | | var tpl = $("#locMapTemplate").html(); |
| | | var tpl = $("#locMastRowTemplate").html(); |
| | | var template = Handlebars.compile(tpl); |
| | | var html = template(res.data); |
| | | $('#locMap').html(html); |
| | | $('#rowSelect').append(template(res)); |
| | | form.render('select'); |
| | | } else if (res.code === 403) { |
| | | top.location.href = baseUrl; |
| | | } else { |
| | | layer.msg(res.msg) |
| | | top.location.href = baseUrl + "/"; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | form.on('select(row)', function (data) { |
| | | getLocTable(data.value); |
| | | }); |
| | | }); |
| | | |
| | | var locNo = ''; |
| | | function locDetl(el) { |
| | | var value = $(el).attr('title'); |
| | | var html = $(el).html(); |
| | | if (value===null |
| | | ||value === undefined |
| | | || value.trim()==='' |
| | | || html.trim()==='S' |
| | | || html.trim()==='D' |
| | | || html.trim()==='O' |
| | | ){ |
| | | |
| | | } else { |
| | | layer.open({ |
| | | type: 2, |
| | | title: '库位物料', |
| | | maxmin: true, |
| | | area: [top.detailWidth, top.detailHeight], |
| | | shadeClose: true, |
| | | content: 'locDetl.html', |
| | | success: function(layero, index){ |
| | | locNo = value; |
| | | // 加载所有可用层(需要后端支持新接口) |
| | | function loadLayersOptions() { |
| | | $.ajax({ |
| | | url: baseUrl + "/report/viewLocMapList/layers.action", // ← 需要新增接口 |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | method: 'POST', |
| | | async: false, |
| | | success: function (res) { |
| | | if (res.code === 200) { |
| | | var tpl = $("#locMastRowTemplate").html(); // 复用模板 |
| | | var template = Handlebars.compile(tpl); |
| | | $('#layerSelect').append(template(res)); |
| | | form.render('select'); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | // 核心:根据模式加载库位表 |
| | | function getLocTable(mode, value) { |
| | | var url = baseUrl + "/report/viewLocMapList.action"; |
| | | var data = {}; |
| | | |
| | | if (mode === 'byRow') { |
| | | data.row = value; |
| | | } else if (mode === 'byLayer') { |
| | | data.layer = value; |
| | | } |
| | | $.ajax({ |
| | | url: url, |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: data, |
| | | method: 'POST', |
| | | success: function (res) { |
| | | if (res.code === 200) { |
| | | var tpl = $("#locMapTemplate").html(); |
| | | var template = Handlebars.compile(tpl); |
| | | $('#locMap').html(template(res.data)); |
| | | } else if (res.code === 403) { |
| | | top.location.href = baseUrl + "/"; |
| | | } else { |
| | | layer.msg(res.msg || '加载失败'); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 监听 显示模式 切换 |
| | | form.on('select(viewMode)', function (data) { |
| | | var mode = data.value; |
| | | |
| | | if (mode === 'byRow') { |
| | | $('#rowSelectBox').show(); |
| | | $('#layerSelectBox').hide(); |
| | | // 读取当前选中的排 |
| | | var currentRow = $('#rowSelect').val() || 1; |
| | | getLocTable('byRow', currentRow); |
| | | } else if (mode === 'byLayer') { |
| | | $('#rowSelectBox').hide(); |
| | | $('#layerSelectBox').show(); |
| | | var currentLayer = $('#layerSelect').val() || 1; |
| | | getLocTable('byLayer', currentLayer); |
| | | } |
| | | }); |
| | | |
| | | // 监听 排 变化 |
| | | form.on('select(row)', function (data) { |
| | | if ($('#viewMode').val() === 'byRow') { |
| | | getLocTable('byRow', data.value); |
| | | } |
| | | }); |
| | | |
| | | // 监听 层 变化 |
| | | form.on('select(layer)', function (data) { |
| | | if ($('#viewMode').val() === 'byLayer') { |
| | | getLocTable('byLayer', data.value); |
| | | } |
| | | }); |
| | | }); |