|   | 
| var matData = []; | 
| var cstmrVal; | 
| var itemVal; | 
|   | 
| function getCol() { | 
|     var cols = [ | 
|         {field: 'count', align: 'center',title: '出库数量', edit:'text', width: 130,  style:'color: blue;font-weight: bold'} | 
|     ]; | 
|     arrRemove(matCols,  'field', 'anfme'); | 
|     cols.push.apply(cols, matCols); | 
|     cols.push( | 
|             {field: 'stock', align: 'center',title: '库存余量', style: 'font-weight: bold'}, | 
|             {fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:65} | 
|         ) | 
|     return cols; | 
| } | 
| layui.config({ | 
|     base: baseUrl + "/static/layui/lay/modules/" | 
| }).extend({ | 
|     notice: 'notice/notice', | 
| }).use(['table','laydate', 'form', 'admin', 'notice', 'xmSelect'], function() { | 
|     var table = layui.table; | 
|     var $ = layui.jquery; | 
|     var layer = layui.layer; | 
|     var form = layui.form; | 
|     var notice = layui.notice; | 
|     var layDate = layui.laydate; | 
|     var admin = layui.admin; | 
|     var xmSelect = layui.xmSelect; | 
|   | 
|     tableIns = table.render({ | 
|         elem: '#chooseData', | 
|         headers: {token: localStorage.getItem('token')}, | 
|         data: [], | 
|         limit: 100, | 
|         even: true, | 
|         toolbar: '#toolbar', | 
|         cellMinWidth: 50, | 
|         cols: [getCol()], | 
|         done: function(res, curr, count) { | 
|             limit(); | 
|         } | 
|     }); | 
|   | 
|     // 页面修改 | 
|     table.on('edit(chooseData)', function (obj) { | 
|         updateMatData(obj.data.locNo, obj.data.matnr, Number(obj.value)); | 
|     }); | 
|   | 
|     // 监听头工具栏事件 | 
|     table.on('toolbar(chooseData)', function (obj) { | 
|         var data = matData; | 
|         switch (obj.event) { | 
|             case 'createDoc': | 
|                 if (data.length === 0){ | 
|                     notice.error({ | 
|                         title: '消息通知', | 
|                         message: '请添加物料' | 
|                     }); | 
|                 } else { | 
|                     var success = true; | 
|                     for (var i=0;i<matData.length;i++) { | 
|                         if (matData[i].count <= 0) { | 
|                             notice.error({ | 
|                                 title: '消息通知', | 
|                                 message: matData[i].matnr + '物料数量必须大于零!' | 
|                             }); | 
|                             success = false; | 
|                             return false; | 
|                         } | 
|                     } | 
|                     var index = layer.load(1, {shade: [0.1,'#000']}); | 
|                     // 单据类型 | 
|                     var docTypeData; | 
|                     $.ajax({ | 
|                         url: baseUrl+"/work/docType/all/get", | 
|                         headers: {'token': localStorage.getItem('token')}, | 
|                         method: 'POST', | 
|                         async: false, | 
|                         success: function (res) { | 
|                             if (res.code === 200){ | 
|                                 docTypeData = res; | 
|                             } else { | 
|                                 layer.msg(res.msg, {icon: 2}) | 
|                             } | 
|                         } | 
|                     }); | 
|                     var tpl1 = $('#docTypeSelectTpl').html(); | 
|                     var template1 = Handlebars.compile(tpl1); | 
|                     var html1 = template1(docTypeData); | 
|                     $("#docType").html(html1); | 
|   | 
|                     // 客户 | 
|                     var cstmrData; | 
|                     // $.ajax({ | 
|                     //     url: baseUrl+"/work/cstmr/all/get", | 
|                     //     headers: {'token': localStorage.getItem('token')}, | 
|                     //     method: 'POST', | 
|                     //     async: false, | 
|                     //     success: function (res) { | 
|                     //         if (res.code === 200){ | 
|                     //             cstmrData = res; | 
|                     //         } else { | 
|                     //             layer.msg(res.msg, {icon: 2}) | 
|                     //         } | 
|                     //     } | 
|                     // }); | 
|                     // var tpl2 = $('#cstmrSelectTpl').html(); | 
|                     // var template2 = Handlebars.compile(tpl2); | 
|                     // var html2 = template2(cstmrData); | 
|                     // $("#cstmr").html(html2); | 
|                     // 单选 | 
|                     $.ajax({ | 
|                         url: baseUrl+"/work/cstmr/all/get/kv", | 
|                         headers: {'token': localStorage.getItem('token')}, | 
|                         method: 'POST', | 
|                         async: false, | 
|                         success: function (res) { | 
|                             if (res.code === 200){ | 
|                                 cstmrData = res.data; | 
|                             } else { | 
|                                 layer.msg(res.msg, {icon: 2}) | 
|                             } | 
|                         } | 
|                     }); | 
|                     cstmrVal = xmSelect.render({ | 
|                         el: '#cstmr', | 
|                         radio: true, | 
|                         clickClose: true, | 
|                         filterable: true, | 
|                         create: function(val, arr){ | 
|                             if(arr.length === 0){ | 
|                                 return { | 
|                                     name:  val, | 
|                                     value: val | 
|                                 } | 
|                             } | 
|                         }, | 
|                         model: { | 
|                             icon: 'hidden', | 
|                             label: { | 
|                                 type: 'text', | 
|                             } | 
|                         }, | 
|                         data: cstmrData | 
|                     }) | 
|   | 
|                     // 项目 | 
|                     var itemData; | 
|                     // $.ajax({ | 
|                     //     url: baseUrl+"/work/item/all/get", | 
|                     //     headers: {'token': localStorage.getItem('token')}, | 
|                     //     method: 'POST', | 
|                     //     async: false, | 
|                     //     success: function (res) { | 
|                     //         if (res.code === 200){ | 
|                     //             itemData = res; | 
|                     //         } else { | 
|                     //             layer.msg(res.msg, {icon: 2}); | 
|                     //         } | 
|                     //     } | 
|                     // }); | 
|                     // var tpl3 = $('#itemSelectTpl').html(); | 
|                     // var template3 = Handlebars.compile(tpl3); | 
|                     // var html3 = template3(itemData); | 
|                     // $("#item").html(html3); | 
|                     $.ajax({ | 
|                         url: baseUrl+"/work/item/all/get/kv", | 
|                         headers: {'token': localStorage.getItem('token')}, | 
|                         method: 'POST', | 
|                         async: false, | 
|                         success: function (res) { | 
|                             if (res.code === 200){ | 
|                                 itemData = res.data; | 
|                             } else { | 
|                                 layer.msg(res.msg, {icon: 2}); | 
|                             } | 
|                         } | 
|                     }); | 
|                     itemVal = xmSelect.render({ | 
|                         el: '#item', | 
|                         radio: true, | 
|                         clickClose: true, | 
|                         filterable: true, | 
|                         create: function(val, arr){ | 
|                             if(arr.length === 0){ | 
|                                 return { | 
|                                     name:  val, | 
|                                     value: val | 
|                                 } | 
|                             } | 
|                         }, | 
|                         model: { | 
|                             icon: 'hidden', | 
|                             label: { | 
|                                 type: 'text', | 
|                             } | 
|                         }, | 
|                         data: itemData | 
|                     }) | 
|   | 
|                     // 弹窗 | 
|                     layer.close(index); | 
|                     if (success) { | 
|                         admin.open({ | 
|                             type: 1, | 
|                             title: '单据填充', | 
|                             offset: '100px', | 
|                             area: ['360px'], | 
|                             shade: 0.3, | 
|                             content: $('#getOrderNo'), | 
|                             success: function(layero, index){ | 
|                                 layer.iframeAuto(index); | 
|                                 $(layero).children('.layui-layer-content').css('overflow', 'visible'); | 
|                                 layui.form.render('select'); | 
|                             }, | 
|                             cancel: function () { | 
|                                 $('#orderNo').val(''); | 
|                             } | 
|                         }); | 
|                     } | 
|                 } | 
|                 break; | 
|         } | 
|     }); | 
|   | 
|   | 
|     // // 多选 | 
|     // var demo1 = xmSelect.render({ | 
|     //     el: '#demo1', | 
|     //     filterable: true, | 
|     //     create: function(val, arr){ | 
|     //         if(arr.length === 0){ | 
|     //             return { | 
|     //                 name:  val, | 
|     //                 value: val | 
|     //             } | 
|     //         } | 
|     //     }, | 
|     //     data: [ | 
|     //         {name: '张三', value: 1, selected: true}, | 
|     //         {name: '李四', value: 2}, | 
|     //         {name: '王五', value: 3, disabled: true}, | 
|     //     ] | 
|     // }) | 
|   | 
|     // 监听行工具事件 | 
|     table.on('tool(chooseData)', function(obj){ | 
|         var data = obj.data; | 
|         switch (obj.event) { | 
|             case 'remove': | 
|                 for (var i = matData.length - 1; i >= 0; i--) { | 
|                     if (matData[i].matnr === data.matnr) { | 
|                         matData.splice(i, 1); | 
|                     } | 
|                 } | 
|                 tableIns.reload({data: matData,done:function (res) { | 
|                     limit(); | 
|                 }}); | 
|                 break; | 
|         } | 
|     }); | 
|   | 
|     // 开始生成拣货单 | 
|     form.on('submit(confirm)', function (data) { | 
|         var matDetls = []; | 
|         matData.forEach(function(elem) { | 
|             matDetls.push({ | 
|                 matnr: elem.matnr | 
|                 , count: elem.count | 
|             }); | 
|         }); | 
|         var req = JSON.stringify({ | 
|             docType: data.field.docType | 
|             , orderNo: data.field.orderNo | 
|             , orderTime: data.field.orderTime | 
|             , item: itemVal.getValue()[0] ? itemVal.getValue()[0].name : null | 
|             , cstmr: cstmrVal.getValue()[0] ? cstmrVal.getValue()[0].name : null | 
|             , list: matDetls | 
|         }) | 
|         $.ajax({ | 
|             url: baseUrl+"/work/order/init", | 
|             headers: {'token': localStorage.getItem('token')}, | 
|             data: req, | 
|             contentType:'application/json;charset=UTF-8', | 
|             method: 'POST', | 
|             success: function (res) { | 
|                 if (res.code === 200){ | 
|                     notice.success({ | 
|                         title: '消息通知', | 
|                         message: res.msg | 
|                     }); | 
|                     top.layui.layer.close(top.popupRight); | 
|                 } else if (res.code === 403){ | 
|                     top.location.href = baseUrl+"/"; | 
|                 } else { | 
|                     notice.error({ | 
|                         title: '消息通知', | 
|                         message: res.msg | 
|                     }); | 
|                 } | 
|             } | 
|         }); | 
|     }) | 
|   | 
|     function updateMatData(locNo, matnr, count) { | 
|         if (isNaN(count)) { | 
|             notice.error({ | 
|                 title: '消息通知', | 
|                 message: '请输入数字' | 
|             }); | 
|         } else { | 
|             if (count > 0) { | 
|                 for (var i=0;i<matData.length;i++){ | 
|                     if (matData[i]["matnr"] === matnr){ | 
|                         matData[i]["count"] = count; | 
|                         break; | 
|                     } | 
|                 } | 
|             } else { | 
|                 notice.error({ | 
|                     title: '消息通知', | 
|                     message: '数量必须大于零' | 
|                 }); | 
|             } | 
|         } | 
|         tableIns.reload({data: matData,done:function (res) { | 
|             limit(); | 
|         }}); | 
|     } | 
|   | 
|     layDate.render({ | 
|         elem: '#orderTime', | 
|         trigger: 'click', | 
|         type: 'date' | 
|     }); | 
|   | 
| }) | 
|   | 
| // 提取物料 | 
| var matDetlLayerIdx; | 
| function getMatDetl() { | 
|     matDetlLayerIdx = layer.open({ | 
|         type: 2, | 
|         title: '提取出库物料', | 
|         maxmin: true, | 
|         area: [top.detailWidth, top.detailHeight], | 
|         shadeClose: true, | 
|         content: 'matQueryBox.html', | 
|         success: function(layero, index){ | 
|         } | 
|     }); | 
| } | 
|   | 
| // 添加表格数据 | 
| function addTableData(data) { | 
|     for (var i=0;i<data.length;i++){ | 
|         let pass = false; | 
|         for (var j=0;j<matData.length;j++){ | 
|             if (data[i].matnr === matData[j].matnr) { | 
|                 pass = true; | 
|                 break; | 
|             } | 
|         } | 
|         if (pass) { | 
|             data.splice(i--, 1); | 
|         } else { | 
|             data[i]["count"] = 0; | 
|         } | 
|   | 
|     } | 
|     matData.push.apply(matData, data); | 
|     tableIns.reload({data: matData}); | 
|     layer.close(matDetlLayerIdx); | 
| } | 
|   | 
| function initOrderNo() { | 
|     $.ajax({ | 
|         url: baseUrl+"/work/orderNo/init", | 
|         headers: {'token': localStorage.getItem('token')}, | 
|         async: false, | 
|         method: 'GET', | 
|         success: function (res) { | 
|             if (res.code === 200){ | 
|                 $('#orderNo').val(res.data) | 
|             } else if (res.code === 403){ | 
|                 top.location.href = baseUrl+"/"; | 
|             } else { | 
|                 notice.error({ | 
|                     title: '消息通知', | 
|                     message: res.msg | 
|                 }); | 
|             } | 
|         } | 
|     }); | 
| } |