No Description

projectEdit.js 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Created by TT on 2017/8/14.
  3. */
  4. ;
  5. spa_define(function () {
  6. return $.use(["spa", "util", "form"], function (spa, util, fb) {
  7. return {
  8. modal: function (data) {
  9. var root = spa.findInModal(".sys_professornew_project");
  10. var form = fb.build(root.find(".newForm"));
  11. var date = new Date(),
  12. month = date.getMonth() + 1,
  13. myDate = "" + date.getFullYear() + (month > 9 ? month : ("0" + month));
  14. var saveBtn = root.find(".opt-save"),
  15. save = function () {
  16. if (form.val().name) {
  17. var name = trim(form.val().name);
  18. if (name.length > 50) {
  19. util.alert("项目名称不得超过50个字");
  20. return;
  21. }
  22. } else {
  23. util.alert("请填写项目名称");
  24. return;
  25. }
  26. if (form.val().descp) {
  27. var descp = trim(form.val().descp);
  28. if (descp.length > 200) {
  29. util.alert("项目描述不得超过200个字");
  30. return;
  31. }
  32. }
  33. if (!form.val().startMonth && form.val().stopMonth) {
  34. util.alert("没有选择开始时间");
  35. return;
  36. }
  37. if (form.val().startMonth && form.val().stopMonth) {
  38. form.val().startMonth = form.val().startMonth.substring(0, 6);
  39. form.val().stopMonth = form.val().stopMonth.substring(0, 6);
  40. }
  41. form.doPut("../ajax/project",function () {
  42. spa.closeModal();
  43. if (data.hand){
  44. data.hand();
  45. }
  46. },function (data) {
  47. util.alert(data.msg);
  48. })
  49. };
  50. root.find(".modal-ctrl .icon-times").on("click", function () {
  51. spa.closeModal();
  52. });
  53. saveBtn.on("click", save);
  54. form.val(data.data);
  55. if (data.data.stopMonth) {
  56. if (trim(data.data.stopMonth) == "至今") {
  57. form.val({stopMonth: ""});
  58. }
  59. }
  60. function trim(str) { //删除左右两端的空格   
  61. return str.replace(/(^\s*)|(\s*$)/g, "");
  62. }
  63. }
  64. }
  65. });
  66. });