matposAdd.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. layui.use(['form', 'laydate'], function () {
  2. var form = layui.form;
  3. var laydate = layui.laydate;
  4. console.log(window.location.href);
  5. var id = QueryString('id');
  6. if (id == null || id == undefined || id == '') {
  7. id = EmptyId;
  8. }
  9. if (id != EmptyId) {
  10. getById(id, form);
  11. }
  12. form.on('submit(*)', function (data) {
  13. var obj = {
  14. ID: id,
  15. FCode: data.field.FCode,
  16. FL: data.field.FL,
  17. FW: data.field.FW,
  18. FH: data.field.FH,
  19. Remark: data.field.Remark
  20. };
  21. $.ajax({
  22. url: '/mes/api/matpos/add',
  23. contentType: 'application/json',
  24. type: 'post',
  25. dataType: 'text',
  26. data: JSON.stringify(obj),
  27. success: function (res) {
  28. var result = res == EmptyId ? '失败' : '成功';
  29. var content = id == EmptyId ? '添加' : '修改';
  30. var iconId = res == EmptyId ? 2 : 1;
  31. var animateId = res == EmptyId ? 6 : 0;
  32. id = res;
  33. if (res != EmptyId) {
  34. layer.msg(content + result, {
  35. icon: iconId,
  36. anim: animateId
  37. });
  38. getById(res, form);
  39. parent.reloadTable();
  40. } else {
  41. layer.msg('网络错误,请联系管理员', {
  42. icon: 2,
  43. animateId: 6
  44. })
  45. }
  46. }
  47. });
  48. return false;
  49. });
  50. $('#btnAddContinue').click(function () {
  51. id = EmptyId;
  52. });
  53. $('#btnCopy').click(function () {
  54. id = EmptyId;
  55. form.val('addForm', {
  56. FCode: ''
  57. })
  58. });
  59. });
  60. function getById(id, form) {
  61. $.ajax({
  62. url: '/mes/api/matpos/' + id,
  63. type: 'get',
  64. dataType: 'json',
  65. success: function (res) {
  66. form.val('addForm', {
  67. FCode: res.fCode,
  68. FL: res.fl,
  69. FW: res.fw,
  70. FH: res.fh,
  71. FStatusName: res.fStatusName,
  72. Remark: res.remark
  73. });
  74. }
  75. });
  76. }