expert_info.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * 初始化expert详情对话框
  3. */
  4. var ExpertInfoDlg = {
  5. expertInfoData : {},
  6. validateFields: {
  7. name: {
  8. validators: {
  9. notEmpty: {
  10. message: '专家姓名不能为空'
  11. }
  12. }
  13. },
  14. phone: {
  15. validators: {
  16. notEmpty: {
  17. message: '联系方式不能为空'
  18. },
  19. regexp: {
  20. regexp: /^1\d{10}$/,
  21. message: '手机号格式错误'
  22. }
  23. }
  24. },
  25. state: {
  26. validators: {
  27. notEmpty: {
  28. message: '有效状态不能为空'
  29. }
  30. }
  31. },
  32. }
  33. };
  34. /**
  35. * 清除数据
  36. */
  37. ExpertInfoDlg.clearData = function() {
  38. this.expertInfoData = {};
  39. }
  40. /**
  41. * 设置对话框中的数据
  42. *
  43. * @param key 数据的名称
  44. * @param val 数据的具体值
  45. */
  46. ExpertInfoDlg.set = function(key, val) {
  47. this.expertInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
  48. return this;
  49. }
  50. /**
  51. * 设置对话框中的数据
  52. *
  53. * @param key 数据的名称
  54. * @param val 数据的具体值
  55. */
  56. ExpertInfoDlg.get = function(key) {
  57. return $("#" + key).val();
  58. }
  59. /**
  60. * 关闭此对话框
  61. */
  62. ExpertInfoDlg.close = function() {
  63. parent.layer.close(window.parent.Expert.layerIndex);
  64. }
  65. /**
  66. * 收集数据
  67. */
  68. ExpertInfoDlg.collectData = function() {
  69. this.set('id')
  70. .set('name')
  71. .set('phone')
  72. .set('description')
  73. .set('state');
  74. }
  75. /**
  76. * 验证数据是否为空
  77. */
  78. ExpertInfoDlg.validate = function () {
  79. $('#expertInfoForm').data("bootstrapValidator").resetForm();
  80. $('#expertInfoForm').bootstrapValidator('validate');
  81. return $("#expertInfoForm").data('bootstrapValidator').isValid();
  82. }
  83. /**
  84. * 提交添加
  85. */
  86. ExpertInfoDlg.addSubmit = function() {
  87. this.clearData();
  88. this.collectData();
  89. if (!this.validate()) {
  90. return;
  91. }
  92. //提交信息
  93. var ajax = new $ax(Feng.ctxPath + "/expert/add", function(data){
  94. Feng.success(data.msg);
  95. if(data.code=="200"){
  96. window.parent.Expert.table.refresh();
  97. ExpertInfoDlg.close();
  98. }
  99. },function(data){
  100. Feng.error("添加失败!" + data.responseJSON.message + "!");
  101. });
  102. ajax.set(this.expertInfoData);
  103. ajax.start();
  104. }
  105. /**
  106. * 提交修改
  107. */
  108. ExpertInfoDlg.editSubmit = function() {
  109. this.clearData();
  110. this.collectData();
  111. if (!this.validate()) {
  112. return;
  113. }
  114. //提交信息
  115. var ajax = new $ax(Feng.ctxPath + "/expert/update", function(data){
  116. Feng.success("修改成功!");
  117. window.parent.Expert.table.refresh();
  118. ExpertInfoDlg.close();
  119. },function(data){
  120. Feng.error("修改失败!" + data.responseJSON.message + "!");
  121. });
  122. ajax.set(this.expertInfoData);
  123. ajax.start();
  124. }
  125. $(function() {
  126. Feng.initValidator("expertInfoForm", ExpertInfoDlg.validateFields);
  127. });
  128. // 验证手机号
  129. function checkMobile(str) {
  130. let re = /^1\d{10}$/
  131. if (re.test(str)) {
  132. return true;
  133. } else {
  134. return false;
  135. }
  136. }