staffAdd.js 2.4 KB

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