layui.use(['form', 'laydate'], function () { var form = layui.form; var laydate = layui.laydate; console.log(window.location.href); var id = QueryString('id'); if (id == null || id == undefined || id == '') { id = EmptyId; } if (id != EmptyId) { getById(id, form); } form.on('submit(*)', function (data) { var obj = { ID: id, FCode: data.field.FCode, FL: data.field.FL, FW: data.field.FW, FH: data.field.FH, Remark: data.field.Remark }; $.ajax({ url: '/mes/api/matpos/add', contentType: 'application/json', type: 'post', dataType: 'text', data: JSON.stringify(obj), success: function (res) { var result = res == EmptyId ? '失败' : '成功'; var content = id == EmptyId ? '添加' : '修改'; var iconId = res == EmptyId ? 2 : 1; var animateId = res == EmptyId ? 6 : 0; id = res; if (res != EmptyId) { layer.msg(content + result, { icon: iconId, anim: animateId }); getById(res, form); parent.reloadTable(); } else { layer.msg('网络错误,请联系管理员', { icon: 2, animateId: 6 }) } } }); return false; }); $('#btnAddContinue').click(function () { id = EmptyId; }); $('#btnCopy').click(function () { id = EmptyId; form.val('addForm', { FCode: '' }) }); }); function getById(id, form) { $.ajax({ url: '/mes/api/matpos/' + id, type: 'get', dataType: 'json', success: function (res) { form.val('addForm', { FCode: res.fCode, FL: res.fl, FW: res.fw, FH: res.fh, FStatusName: res.fStatusName, Remark: res.remark }); } }); }