macmodelAdd.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. layui.use('form', function () {
  2. var form = layui.form;
  3. console.log(window.location.href);
  4. var id = QueryString('id');
  5. if (id == null || id == undefined || id == '') {
  6. id = '0';
  7. }
  8. if (id != '0') {
  9. $.ajax({
  10. url: '/mes/api/macmodel/' + id,
  11. type: 'get',
  12. dataType: 'json',
  13. success: function (res) {
  14. form.val('addForm', {
  15. FCode: res.fCode,
  16. FName: res.fName,
  17. TPCode: res.tpCode,
  18. Remark: res.remark
  19. });
  20. }
  21. });
  22. }
  23. form.on('submit(*)', function (data) {
  24. var obj = {
  25. ID: id,
  26. FCode: data.field.FCode,
  27. FName: data.field.FName,
  28. TPCode: data.field.TPCode,
  29. Remark: data.field.Remark
  30. };
  31. $.ajax({
  32. url: '/mes/api/macmodel/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/macmodel/' + res,
  50. type: 'get',
  51. dataType: 'json',
  52. success: function (res) {
  53. form.val('addForm', {
  54. FCode: res.fCode,
  55. FName: res.fName,
  56. TPCode: res.tpCode,
  57. Remark: res.remark
  58. });
  59. }
  60. });
  61. parent.reloadTable();
  62. } else {
  63. layer.msg('网络错误,请联系管理员', {
  64. icon: 2,
  65. animateId: 6
  66. })
  67. }
  68. }
  69. });
  70. return false;
  71. });
  72. $('#btnAddContinue').click(function () {
  73. id = '0';
  74. });
  75. });