editStaff.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. 编辑员工
  3. **/
  4. (function(vc){
  5. vc.extends({
  6. data:{
  7. editStaffInfo:{
  8. userId:'',
  9. username:'',
  10. email:'',
  11. tel:'',
  12. sex:'',
  13. address:'',
  14. errorInfo:'',
  15. }
  16. },
  17. _initMethod:function(){
  18. },
  19. _initEvent:function(){
  20. vc.component.$on('edit_staff_event',function(_staffInfo){
  21. vc.component.refreshEditStaffInfo(_staffInfo);
  22. $('#editStaffModel').modal('show');
  23. });
  24. },
  25. methods:{
  26. refreshEditStaffInfo(_staffInfo){
  27. vc.component.editStaffInfo.userId = _staffInfo.userId;
  28. vc.component.editStaffInfo.username = _staffInfo.name;
  29. vc.component.editStaffInfo.email = _staffInfo.email;
  30. vc.component.editStaffInfo.tel = _staffInfo.tel;
  31. vc.component.editStaffInfo.sex = _staffInfo.sex;
  32. vc.component.editStaffInfo.address = _staffInfo.address;
  33. },
  34. editStaffValidate(){
  35. return vc.validate.validate({
  36. editStaffInfo:vc.component.editStaffInfo
  37. },{
  38. 'editStaffInfo.username':[
  39. {
  40. limit:"required",
  41. param:"",
  42. errInfo:"用户名不能为空"
  43. },
  44. {
  45. limit:"maxin",
  46. param:"2,10",
  47. errInfo:"用户名长度必须在2位至10位"
  48. },
  49. ],
  50. 'editStaffInfo.email':[
  51. {
  52. limit:"required",
  53. param:"",
  54. errInfo:"密码不能为空"
  55. },
  56. {
  57. limit:"email",
  58. param:"",
  59. errInfo:"不是有效的邮箱"
  60. },
  61. ],
  62. 'editStaffInfo.tel':[
  63. {
  64. limit:"required",
  65. param:"",
  66. errInfo:"手机号不能为空"
  67. },
  68. {
  69. limit:"phone",
  70. param:"",
  71. errInfo:"不是有效的手机号"
  72. }
  73. ],
  74. 'editStaffInfo.sex':[
  75. {
  76. limit:"required",
  77. param:"",
  78. errInfo:"性别不能为空"
  79. }
  80. ],
  81. 'editStaffInfo.address':[
  82. {
  83. limit:"required",
  84. param:"",
  85. errInfo:"地址不能为空"
  86. },
  87. {
  88. limit:"maxLength",
  89. param:"200",
  90. errInfo:"地址长度不能超过200位"
  91. },
  92. ]
  93. });
  94. },
  95. editStaffInfo:function(){
  96. if(!vc.component.editStaffValidate()){
  97. vc.component.editStaffInfo.errorInfo = vc.validate.errInfo;
  98. return ;
  99. }
  100. vc.component.editStaffInfo.errorInfo = "";
  101. vc.http.post(
  102. 'editStaff',
  103. 'modifyStaff',
  104. JSON.stringify(vc.component.editStaffInfo),
  105. {
  106. emulateJSON:true
  107. },
  108. function(json,res){
  109. //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
  110. if(res.status == 200){
  111. //关闭model
  112. $('#editStaffModel').modal('hide');
  113. vc.component.$emit('editStaff_reload_event',{});
  114. return ;
  115. }
  116. vc.component.editStaffInfo.errorInfo = json;
  117. },
  118. function(errInfo,error){
  119. console.log('请求失败处理');
  120. vc.component.editStaffInfo.errorInfo = errInfo;
  121. });
  122. }
  123. },
  124. });
  125. })(window.vc);