processAdd.js 2.4 KB

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