Keine Beschreibung

edit.js 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Created by TT on 2017/7/7.
  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_userinfo_edit");
  10. var form = fb.build(root.find(".newForm"));
  11. var trim = function (str) {
  12. return str.replace(/(^\s*)|(\s*$)/g, "");
  13. };
  14. var saveBtn = root.find(".opt-save"),
  15. save = function () {
  16. if (form.val().mobile) {
  17. var mobile = trim(form.val().mobile);
  18. var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
  19. if (!hunPhone.test(mobile)) {
  20. util.alert("注册电话格式有误,请检查后重新填写");
  21. return;
  22. }
  23. }
  24. if (form.val().email) {
  25. var email = trim(form.val().email);
  26. var gunf = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  27. if (!gunf.test(email)) {
  28. util.alert("联系邮箱格式有误,请检查后重新填写");
  29. return;
  30. }
  31. }
  32. if (form.val().name) {
  33. var name = trim(form.val().name);
  34. if (name.length > 10) {
  35. util.alert("姓名最长为10个字");
  36. return;
  37. }
  38. } else {
  39. util.alert("请填写用户名");
  40. return;
  41. }
  42. if (form.val().mobile || form.val().email) {
  43. if (form.val().mobile != data.data.mobile || form.val().email != data.data.email) {
  44. util.get("../ajax/userinfo/editCheck", {
  45. mobile: form.val().mobile,
  46. email: form.val().email,
  47. id:form.val().id
  48. }, function (success) {
  49. if (success) {
  50. form.doPut("../ajax/userinfo/update", function () {
  51. spa.closeModal();
  52. if (data.hand) {
  53. data.hand();
  54. }
  55. }, {});
  56. } else {
  57. util.alert("该账号已存在");
  58. }
  59. });
  60. } else {
  61. form.doPut("../ajax/userinfo/update", closeThis, {});
  62. }
  63. } else {
  64. util.alert("手机或邮箱至少输入一项");
  65. }
  66. };
  67. root.find(".modal-ctrl .icon-times").on("click", function () {
  68. spa.closeModal();
  69. });
  70. var handler = data.hand;
  71. var closeThis = function () {
  72. spa.closeModal();
  73. if (handler) {
  74. handler();
  75. }
  76. };
  77. form.val(data.data);
  78. saveBtn.on("click", save);
  79. }
  80. };
  81. })
  82. });