addCommunity.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. (function(vc){
  2. vc.extends({
  3. data:{
  4. addCommunityInfo:{
  5. name:'',
  6. address:'',
  7. nearbyLandmarks:'',
  8. cityCode:'0971',
  9. mapX:'101.33',
  10. mapY:'101.33',
  11. }
  12. },
  13. _initMethod:function(){
  14. },
  15. _initEvent:function(){
  16. vc.on('addCommunity','openAddCommunityModal',function(){
  17. $('#addCommunityModel').modal('show');
  18. });
  19. },
  20. methods:{
  21. addCommunityValidate(){
  22. return vc.validate.validate({
  23. addCommunityInfo:vc.component.addCommunityInfo
  24. },{
  25. 'addCommunityInfo.name':[
  26. {
  27. limit:"required",
  28. param:"",
  29. errInfo:"小区名称不能为空"
  30. },
  31. {
  32. limit:"maxin",
  33. param:"10,20",
  34. errInfo:"小区名称必须在10至20字符之间"
  35. },
  36. ],
  37. 'addCommunityInfo.address':[
  38. {
  39. limit:"required",
  40. param:"",
  41. errInfo:"小区地址不能为空"
  42. },
  43. {
  44. limit:"maxin",
  45. param:"200",
  46. errInfo:"小区地址不能大于200个字符"
  47. },
  48. ],
  49. 'addCommunityInfo.nearbyLandmarks':[
  50. {
  51. limit:"required",
  52. param:"",
  53. errInfo:"附近地标不能为空"
  54. },
  55. {
  56. limit:"maxin",
  57. param:"50",
  58. errInfo:"小区附近地标不能大于50个字符"
  59. },
  60. ],
  61. 'addCommunityInfo.cityCode':[
  62. {
  63. limit:"maxin",
  64. param:"12",
  65. errInfo:"小区城市编码不能大于4个字符"
  66. },
  67. ],
  68. 'addCommunityInfo.mapX':[
  69. {
  70. limit:"maxin",
  71. param:"20",
  72. errInfo:"小区城市编码不能大于4个字符"
  73. },
  74. ],
  75. 'addCommunityInfo.mapY':[
  76. {
  77. limit:"maxin",
  78. param:"20",
  79. errInfo:"小区城市编码不能大于4个字符"
  80. },
  81. ],
  82. });
  83. },
  84. saveCommunityInfo:function(){
  85. if(!vc.component.addCommunityValidate()){
  86. vc.message(vc.validate.errInfo);
  87. return ;
  88. }
  89. vc.component.addCommunityInfo.communityId = vc.getCurrentCommunity().communityId;
  90. vc.http.post(
  91. 'addCommunity',
  92. 'save',
  93. JSON.stringify(vc.component.addCommunityInfo),
  94. {
  95. emulateJSON:true
  96. },
  97. function(json,res){
  98. //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
  99. if(res.status == 200){
  100. //关闭model
  101. $('#addCommunityModel').modal('hide');
  102. vc.component.clearAddCommunityInfo();
  103. vc.emit('communityManage','listCommunity',{});
  104. return ;
  105. }
  106. vc.message(json);
  107. },
  108. function(errInfo,error){
  109. console.log('请求失败处理');
  110. vc.message(errInfo);
  111. });
  112. },
  113. clearAddCommunityInfo:function(){
  114. vc.component.addCommunityInfo = {
  115. name:'',
  116. address:'',
  117. nearbyLandmarks:'',
  118. cityCode:'0971',
  119. mapX:'101.33',
  120. mapY:'101.33',
  121. };
  122. }
  123. }
  124. });
  125. })(window.vc);